package jesstest;

import jesstest.model.*;
import jess.*;

import java.util.Iterator;

public class RecipientsSelectionEngine {
    private Rete engine;
    private WorkingMemoryMarker marker;
   
    public RecipientsSelectionEngine(Problem problem) throws JessException {
        // Create a Jess rule engine
		  	
		//Sstem.out.println(new Date());		
    	long b = System.currentTimeMillis();
    	engine = new Rete();
        engine.reset();

        // Load the pricing rules
        engine.batch("recipientsselection.clp");
        engine.add(problem);
        marker = engine.mark();
        long e = System.currentTimeMillis();
        System.out.println("It took "+(e-b)+ " milliseconds to intialize JESS.");
		//Average initialization time 1000 milliseconds
    }

    public Iterator run(Profile p) throws JessException {
    	engine.resetToMark(marker);
    	// Load data for this order
    	if (p != null) {
    		// Add the order and its contents to working memory
    		engine.add(p);
    		engine.add(p.getActiveEquipmentConfig());
    	}
    	// Fire the rules that apply to this order
    	engine.run();
    	// Return the list of offers created by the rules
    	return engine.getObjects(new Filter.ByClass(Selected.class));
    }
}